package org.txazo.music.web.action;

import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.txazo.music.service.UserService;
import org.txazo.music.vo.User;
import org.txazo.music.web.action.base.BaseAction;

/**
 * PasswordAction
 * 
 * @author Tu XiaoZhou
 * @since 2013-04-12
 * 
 */
@Controller
@Scope("session")
public class PasswordAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	/** 旧密码 */
	public String oldPassword;
	/** 新密码 */
	public String newPassword;

	/** 提示信息 */
	public String tip;

	@Autowired
	private UserService userService;

	@Action(value = "updatePassword")
	public String updatePassword() {

		User user = (User) session.getAttribute("user");
		if (oldPassword.equals(user.getPassword())) {
			userService.updatePassword(user.getId(), newPassword);
		}

		return SUCCESS;
	}

	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

}
